﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using ChinaSoft.DBUtility;//Please add references
namespace ChinaSoft.DAL
{
	/// <summary>
	/// 数据访问类:DAL_T_SYS_LOGS
	/// </summary>
	public partial class DAL_T_SYS_LOGS
	{
		public DAL_T_SYS_LOGS()
		{}
		#region  Method

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string SYS_LOGS_ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from T_SYS_LOGS");
			strSql.Append(" where SYS_LOGS_ID=:SYS_LOGS_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_LOGS_ID", OracleType.VarChar,40)			};
			parameters[0].Value = SYS_LOGS_ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(ChinaSoft.Model.Model_T_SYS_LOGS model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into T_SYS_LOGS(");
			strSql.Append("SYS_LOGS_ID,OPERATORID,OPERATORNAME,OPERATORIP,OPERATIONCODE,OPERATEENTITY,OPERATETIME,CONTENT,LOGINNAME,OPERATORAREAID,OP_AREA,MODULENAME)");
			strSql.Append(" values (");
			strSql.Append(":SYS_LOGS_ID,:OPERATORID,:OPERATORNAME,:OPERATORIP,:OPERATIONCODE,:OPERATEENTITY,:OPERATETIME,:CONTENT,:LOGINNAME,:OPERATORAREAID,:OP_AREA,:MODULENAME)");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_LOGS_ID", OracleType.VarChar,40),
					new OracleParameter(":OPERATORID", OracleType.VarChar,40),
					new OracleParameter(":OPERATORNAME", OracleType.VarChar,50),
					new OracleParameter(":OPERATORIP", OracleType.VarChar,50),
					new OracleParameter(":OPERATIONCODE", OracleType.VarChar,20),
					new OracleParameter(":OPERATEENTITY", OracleType.VarChar,80),
					new OracleParameter(":OPERATETIME", OracleType.DateTime),
					new OracleParameter(":CONTENT", OracleType.Clob,4000),
					new OracleParameter(":LOGINNAME", OracleType.VarChar,100),
					new OracleParameter(":OPERATORAREAID", OracleType.Number,4),
					new OracleParameter(":OP_AREA", OracleType.VarChar,100),
					new OracleParameter(":MODULENAME", OracleType.VarChar,50)};
			parameters[0].Value = model.SYS_LOGS_ID;
			parameters[1].Value = model.OPERATORID;
			parameters[2].Value = model.OPERATORNAME;
			parameters[3].Value = model.OPERATORIP;
			parameters[4].Value = model.OPERATIONCODE;
			parameters[5].Value = model.OPERATEENTITY;
			parameters[6].Value = model.OPERATETIME;
			parameters[7].Value = model.CONTENT;
			parameters[8].Value = model.LOGINNAME;
			parameters[9].Value = model.OPERATORAREAID;
			parameters[10].Value = model.OP_AREA;
			parameters[11].Value = model.MODULENAME;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ChinaSoft.Model.Model_T_SYS_LOGS model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update T_SYS_LOGS set ");
			strSql.Append("OPERATORID=:OPERATORID,");
			strSql.Append("OPERATORNAME=:OPERATORNAME,");
			strSql.Append("OPERATORIP=:OPERATORIP,");
			strSql.Append("OPERATIONCODE=:OPERATIONCODE,");
			strSql.Append("OPERATEENTITY=:OPERATEENTITY,");
			strSql.Append("OPERATETIME=:OPERATETIME,");
			strSql.Append("CONTENT=:CONTENT,");
			strSql.Append("LOGINNAME=:LOGINNAME,");
			strSql.Append("OPERATORAREAID=:OPERATORAREAID,");
			strSql.Append("OP_AREA=:OP_AREA,");
			strSql.Append("MODULENAME=:MODULENAME");
			strSql.Append(" where SYS_LOGS_ID=:SYS_LOGS_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":OPERATORID", OracleType.VarChar,40),
					new OracleParameter(":OPERATORNAME", OracleType.VarChar,50),
					new OracleParameter(":OPERATORIP", OracleType.VarChar,50),
					new OracleParameter(":OPERATIONCODE", OracleType.VarChar,20),
					new OracleParameter(":OPERATEENTITY", OracleType.VarChar,80),
					new OracleParameter(":OPERATETIME", OracleType.DateTime),
					new OracleParameter(":CONTENT", OracleType.Clob,4000),
					new OracleParameter(":LOGINNAME", OracleType.VarChar,100),
					new OracleParameter(":OPERATORAREAID", OracleType.Number,4),
					new OracleParameter(":OP_AREA", OracleType.VarChar,100),
					new OracleParameter(":MODULENAME", OracleType.VarChar,50),
					new OracleParameter(":SYS_LOGS_ID", OracleType.VarChar,40)};
			parameters[0].Value = model.OPERATORID;
			parameters[1].Value = model.OPERATORNAME;
			parameters[2].Value = model.OPERATORIP;
			parameters[3].Value = model.OPERATIONCODE;
			parameters[4].Value = model.OPERATEENTITY;
			parameters[5].Value = model.OPERATETIME;
			parameters[6].Value = model.CONTENT;
			parameters[7].Value = model.LOGINNAME;
			parameters[8].Value = model.OPERATORAREAID;
			parameters[9].Value = model.OP_AREA;
			parameters[10].Value = model.MODULENAME;
			parameters[11].Value = model.SYS_LOGS_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(string SYS_LOGS_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_SYS_LOGS ");
			strSql.Append(" where SYS_LOGS_ID=:SYS_LOGS_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_LOGS_ID", OracleType.VarChar,40)			};
			parameters[0].Value = SYS_LOGS_ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string SYS_LOGS_IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from T_SYS_LOGS ");
			strSql.Append(" where SYS_LOGS_ID in ("+SYS_LOGS_IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ChinaSoft.Model.Model_T_SYS_LOGS GetModel(string SYS_LOGS_ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select SYS_LOGS_ID,OPERATORID,OPERATORNAME,OPERATORIP,OPERATIONCODE,OPERATEENTITY,OPERATETIME,CONTENT,LOGINNAME,OPERATORAREAID,OP_AREA,MODULENAME from T_SYS_LOGS ");
			strSql.Append(" where SYS_LOGS_ID=:SYS_LOGS_ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":SYS_LOGS_ID", OracleType.VarChar,40)			};
			parameters[0].Value = SYS_LOGS_ID;

			ChinaSoft.Model.Model_T_SYS_LOGS model=new ChinaSoft.Model.Model_T_SYS_LOGS();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["SYS_LOGS_ID"]!=null && ds.Tables[0].Rows[0]["SYS_LOGS_ID"].ToString()!="")
				{
					model.SYS_LOGS_ID=ds.Tables[0].Rows[0]["SYS_LOGS_ID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OPERATORID"]!=null && ds.Tables[0].Rows[0]["OPERATORID"].ToString()!="")
				{
					model.OPERATORID=ds.Tables[0].Rows[0]["OPERATORID"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OPERATORNAME"]!=null && ds.Tables[0].Rows[0]["OPERATORNAME"].ToString()!="")
				{
					model.OPERATORNAME=ds.Tables[0].Rows[0]["OPERATORNAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OPERATORIP"]!=null && ds.Tables[0].Rows[0]["OPERATORIP"].ToString()!="")
				{
					model.OPERATORIP=ds.Tables[0].Rows[0]["OPERATORIP"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OPERATIONCODE"]!=null && ds.Tables[0].Rows[0]["OPERATIONCODE"].ToString()!="")
				{
					model.OPERATIONCODE=ds.Tables[0].Rows[0]["OPERATIONCODE"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OPERATEENTITY"]!=null && ds.Tables[0].Rows[0]["OPERATEENTITY"].ToString()!="")
				{
					model.OPERATEENTITY=ds.Tables[0].Rows[0]["OPERATEENTITY"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OPERATETIME"]!=null && ds.Tables[0].Rows[0]["OPERATETIME"].ToString()!="")
				{
					model.OPERATETIME=DateTime.Parse(ds.Tables[0].Rows[0]["OPERATETIME"].ToString());
				}
				if(ds.Tables[0].Rows[0]["CONTENT"]!=null && ds.Tables[0].Rows[0]["CONTENT"].ToString()!="")
				{
					//model.CONTENT=ds.Tables[0].Rows[0]["CONTENT"].ToString();
				}
				if(ds.Tables[0].Rows[0]["LOGINNAME"]!=null && ds.Tables[0].Rows[0]["LOGINNAME"].ToString()!="")
				{
					model.LOGINNAME=ds.Tables[0].Rows[0]["LOGINNAME"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OPERATORAREAID"]!=null && ds.Tables[0].Rows[0]["OPERATORAREAID"].ToString()!="")
				{
					model.OPERATORAREAID=decimal.Parse(ds.Tables[0].Rows[0]["OPERATORAREAID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["OP_AREA"]!=null && ds.Tables[0].Rows[0]["OP_AREA"].ToString()!="")
				{
					model.OP_AREA=ds.Tables[0].Rows[0]["OP_AREA"].ToString();
				}
				if(ds.Tables[0].Rows[0]["MODULENAME"]!=null && ds.Tables[0].Rows[0]["MODULENAME"].ToString()!="")
				{
					model.MODULENAME=ds.Tables[0].Rows[0]["MODULENAME"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select SYS_LOGS_ID,OPERATORID,OPERATORNAME,OPERATORIP,OPERATIONCODE,OPERATEENTITY,OPERATETIME,CONTENT,LOGINNAME,OPERATORAREAID,OP_AREA,MODULENAME ");
			strSql.Append(" FROM T_SYS_LOGS ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM T_SYS_LOGS ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.SYS_LOGS_ID desc");
			}
			strSql.Append(")AS Row, T.*  from T_SYS_LOGS T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "T_SYS_LOGS";
			parameters[1].Value = "SYS_LOGS_ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

